$(function() {
	$('#vue_vm_list div').hide();
	
	var loginedUser = getLoginedUser();
	loadCaregiverSelectBySubjectRoomId(loginedUser.subjectRoomId);
	
	_addChangeListener("#caregiver_select", function() {
		var option = $('#caregiver_select option:selected');
		if(view && view.data) {view.data.caregiverName = option.text();}
	});
});

function loadCaregiverSelectBySubjectRoomId(subjectRoomId) {
	if($('#caregiver_select').length==0) {return;}

	$('#caregiver_select').html('<option value="" selected></option>');

	find_basic_by_json(path+'/caregiver/findBySubjectRoomId', {subjectRoomId: subjectRoomId}, function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#caregiver_select').append('<option value="' + response.data[i].caregiverId
				+ '">' + response.data[i].name + '</option>');
		}
	});
}

var caregiverGrade = {
	caregiverGradeId: '',
	subjectRoomId: getLoginedUser().subjectRoomId,
	subjectRoomName: getLoginedUser().subjectRoomName,
	caregiverId: '',
	caregiverName: '',
	grade: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
};

var view = {
	data: caregiverGrade
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

function save() {
	view.data.month = $('#year').val() + '-' + $('#month').val();
	view.data.grade = (view.data.grade==''? 0: parseFloat(view.data.grade));

	save_basic(path+'/caregiverGrade/save', {caregiverGrade:view.data}, function() {
		alert('保存成功');
		findAll();
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/caregiverGrade/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/caregiverGrade/deleteBatch');
}
